package Arrays101.Day01;


public class Day01_1 {
    public static void main(String[] args) {
        int maxConsecutiveOnes = findMaxConsecutiveOnes(new int[]{1, 1, 0, 1, 1, 1});
        System.out.println(maxConsecutiveOnes);
    }

    /**
     * Max Consecutive Ones
     *
     * Given a binary array nums, return the maximum number of consecutive 1's in the array.
     * @param nums
     * @return
     */
    public static int findMaxConsecutiveOnes(int[] nums) {
        int temp=0;
        int max=0;
        for (int i = 0; i < nums .length; i++) {

            if (nums [i]==1){
                temp++;
            }else {
                if(temp>max)
                    max=temp;
                temp=0;
            }
        }
        max=Math.max(max,temp);
        return max;
    }
}

